package com.example.service.impl;

import com.example.entity.Orders;
import com.example.DAO.OrdersDao;
import com.example.entity.Users;
import com.example.service.OrdersService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Orders)表服务实现类
 *
 * @author makejava
 * @since 2022-06-06 23:17:19
 */
@Service("ordersService")
public class OrdersServiceImpl implements OrdersService {

    @Resource
    private OrdersDao ordersDao;

    /**
     * 通过ID查询单条数据
     *
     * @param oid 主键
     * @return 实例对象
     */
    @Override
    public Orders queryById(Integer oid) {
        return this.ordersDao.queryById(oid);
    }

    @Override
    public Page<Orders> queryByPage(Orders orders, PageRequest pageRequest) {
        return null;
    }

    /**
     * 分页查询
     *
//      * @param offset 查询起始位置
//         * @param limit  查询条数
//     * @param orders 筛选条件
//     * @param pageRequest      分页对象
     * @return 查询结果
     */
    //    public Page<Orders> queryByPage(Orders orders, PageRequest pageRequest) {
//        long total = this.ordersDao.count(orders);
//        return new PageImpl<>(this.ordersDao.queryAllByLimit(orders, pageRequest),
//                pageRequest, total);
//    }

    @Override
    public List<Orders> queryAllByLimit(int offset, int limit) {
        return this.ordersDao.queryAllByLimit(offset,limit);
    }
    @Override
    public PageInfo<Orders> queryAllByPage(Orders orders, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Orders> ordersList = ordersDao.queryAll(orders);
        PageInfo<Orders> ordersPageInfo = new PageInfo<>(ordersList);
        return ordersPageInfo;

    }

//    @Override
//    public List<Orders> queryAllByLimit(int offset, int limit) {
//        return null;
//    }

    /**
     * 新增数据
     *
     * @param orders 实例对象
     * @return 实例对象
     */
    @Override
    public Orders insert(Orders orders) {
        this.ordersDao.insert(orders);
        return orders;
    }

    /**
     * 修改数据
     *
     * @param orders 实例对象
     * @return 实例对象
     */
    @Override
    public Orders update(Orders orders) {
        this.ordersDao.update(orders);
        return orders;
    }

    /**
     * 通过主键删除数据
     *
     * @param oid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer oid) {
        return this.ordersDao.deleteById(oid) > 0;
    }
}
